<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1> 原生 ajax = XMLHttpRequest</h1>
    <script>
     
     var url  = 'https://autumnfish.cn/api/joke/list?num=3'
     var xhttp = new XMLHttpRequest();
     xhttp.open('GET',url);
     xhttp.send();

     //回调事件
     xhttp.onreadystatechange = function(){
        if(xhttp.readyState == 4 && xhttp.status == 200){
            var ret = xhttp.responseText ;
            console.log( ret )  // string
            var obj = JSON.parse(ret)
            //循环数组
            for(let s of obj.data){
                let p = document.createElement('P')
                p.innerHTML = s ;
                document.body.appendChild( p )
            }
        }
     }



    </script>
</body>
</html>